//
//  LinkingCardInforView.swift
//  iPhone
//
//  Created by Toj on 11/8/22.
//

import UIKit

class LinkingCardInforView: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupAddSubviews()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        setupLayoutSubviews()
    }
    
    private(set) lazy var backgroundView = UIImageView()
    
    private let cardCellHeight = 52.ui_scale
    private(set) lazy var smartcardView: LinkingCardInfoCell = {
        let view = LinkingCardInfoCell()
        view.cm_borderColor = "#FFF3CF".to_color
        view.cm_cornerRadius = cardCellHeight * 0.5
        view.title = "Smartcard:"
        view.text = "23412341234".cm_numberFormat(format: .threeFourFour)
        view.image = "dvb_pre_link_decoder".to_image
        return view
    }()
    
    private lazy var relationImageView: UIImageView = {
        let view = UIImageView()
        view.image = "dvb_pre_link_relation".to_image
        return view
    }()
    
    private(set) lazy var phoneView: LinkingCardInfoCell = {
        let view = LinkingCardInfoCell()
        view.cm_borderColor = "#FFF3CF".to_color
        view.cm_cornerRadius = cardCellHeight * 0.5
        view.title = "Your phone number:"
        view.text = "+86 " + "13412341234".cm_numberFormat(format: .threeFourFour)
        view.image = "dvb_pre_link_phone".to_image
        return view
    }()
    
    deinit {
        // print("-->toj: LinkingCardInforView " + #function)
    }
}

extension LinkingCardInforView {
    
    private func setupAddSubviews() {
        
        addSubview(backgroundView)
        addSubview(smartcardView)
        addSubview(phoneView)
        addSubview(relationImageView)
    }
    
    private func setupLayoutSubviews() {
        backgroundView.snp.makeConstraints { make in
            make.edges.equalTo(self)
        }
        
        smartcardView.snp.makeConstraints { make in
            make.left.right.top.equalTo(self)
            make.height.equalTo(cardCellHeight)
        }
        
        phoneView.snp.makeConstraints { make in
            make.left.right.bottom.equalTo(self)
            make.height.equalTo(cardCellHeight)
        }
        
        relationImageView.snp.makeConstraints { make in
            make.centerY.equalTo(self)
            make.left.equalTo(18.ui_scale)
            make.width.equalTo(16)
            make.height.equalTo(16)
        }
    }
}

